#encoding:utf-8
# @Time : 2021/8/23 23:08 
# @Author : 锦衣大镖客
# @File : read_excle.py 
# @Software: PyCharm
# desc:

import os
import xlrd3

path=os.path.join(os.path.dirname(__file__).split("api_test_frame")[0],"api_test_frame","test_data","test_data.xlsx")
# print(path)
wb=xlrd3.open_workbook(path)  #创建工作簿对象
sheet=wb.sheet_by_index(0)   #创建表格对象
cell_value=sheet.cell_value(2,1)  #直接取值  行列从下标为0开始    第一个值是行，第二个值是列
# print(cell_value)
merged=sheet.merged_cells# 返回一个列表  起始行，结束行，起始列，结束列


def get_merged_value(rlow_index,clow_index):
    cell_value=None
    try:
        for (rlow, rhigt, clow, chigt) in merged:
            if (rlow_index >= rlow and rlow_index < rhigt):  # 行坐标判断
                if (clow_index >= clow and clow_index < chigt):  # 列坐标判断
                    cell_value = sheet.cell_value(rlow, clow)
                    break
                else:
                    cell_value=sheet.cell_value(rlow_index,clow_index)
            else:
                cell_value=sheet.cell_value(rlow_index,clow_index)
        return cell_value
    except BaseException as ba:
        return ba

# for i in range(1,11):
#     print(get_merged_value(i,0))
print(get_merged_value(4,0))
print(sheet.merged_cells)